package com.demoo.zjsu.controller.smartwebsite;

import com.demoo.zjsu.dao.smartwebsite.SmartWebSelectDao;
import com.demoo.zjsu.model.smartwebsite.PageOne;
import com.demoo.zjsu.model.smartwebsite.PageTwo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jshjsh on 2016/8/27.
 * 针对照片的特殊情况做一些处理
 */
@Controller
public class SpecialController {

   @Autowired
    SmartWebSelectDao dao;

//    @Cacheable(value = "smartWeb", key = "#root.methodName")
    @RequestMapping("/smartweb/pageone/{school_condition}")
    public ModelAndView toPageOne(@PathVariable String school_condition,
                                  @RequestParam("category") String category) {
        PageOne pageOnes = dao.findByCategory(category);
        return new ModelAndView("smartweb/"+school_condition).addObject("page", pageOnes);
    }



    /**
     * 大事记
     *
     * @param
     * @return
     */
//    @Cacheable(value = "smartWeb", key = "#root.methodName")
    @RequestMapping("/smartweb/pageone/school_scenery")
    public ModelAndView toPageOnePhoto(@RequestParam("sort") int sort) {
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("category", "校园风光");
        maps.put("sort", sort);
        maps.put("limit", 12);
        List<PageTwo> pageTwos = dao.findPageTwoLimitSort(maps);
        int size = pageTwos.size();
        return new ModelAndView("smartweb/school_scenery")
                .addObject("size", size)
                .addObject("sort", sort)
                .addObject("page", pageTwos);
    }



//    @Cacheable(value = "smartWeb", key = "#root.methodName")
    @RequestMapping("/smartweb/pageone/bigthing")
    public ModelAndView toPageOneBigThing(@RequestParam("category") String category, @RequestParam("sort") int sort) {
        List<PageTwo> pageOnes = dao.findPageTwoSort(category, sort, 10);
        int size = pageOnes.size();
        return new ModelAndView("smartweb/bigthing")
                .addObject("size", size)
                .addObject("sort", sort)
                .addObject("page", pageOnes);
    }




    @RequestMapping("/smartweb/pagetwocontent/{page}")
    public ModelAndView toPageTwoContentByKey(@PathVariable String page, @RequestParam("key") String key) {
        PageTwo content = dao.selectPageContentById(key);
        return new ModelAndView("smartweb/" + page).addObject("page", content);
    }

}
